package com.offcn.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.offcn.pojo.TCheckgroup;
import com.offcn.service.TCheckgroupService;
import com.offcn.util.MessageConstant;
import com.offcn.util.PageResult;
import com.offcn.util.QueryPageBean;
import com.offcn.util.Result;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjq
 * @since 2021-08-09
 */
@RestController
@RequestMapping("checkgroup")
public class TCheckgroupController {
    @Reference
    private TCheckgroupService tcheckgroupService;
   /* @PostMapping("findPage")
    public Result findPage(@RequestBody QueryPageBean PageBean){
        try {
            PageResult pafe = tCheckgroupService.findPafe(PageBean);
            return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,pafe);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_CHECKGROUP_FAIL,null);

        }

    }*/
   //分页查询
   @PostMapping("findPage")
   public Result findPage(@RequestBody QueryPageBean pageBean){
       try{
           PageResult pageResult = tcheckgroupService.findPage(pageBean);
           return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,pageResult);
       }catch (Exception e){
           e.printStackTrace();
           return new Result(false, MessageConstant.QUERY_CHECKGROUP_FAIL,null);
       }
   }

   //添加
    @PostMapping("add")
    public Result add(int[]checkitemIds, @RequestBody TCheckgroup tCheckgroup){
       try {
            tcheckgroupService.add(checkitemIds,tCheckgroup);
           return new Result(true,MessageConstant.ADD_CHECKGROUP_SUCCESS,null);
       }catch (Exception e){
           e.printStackTrace();
           return new Result(false,MessageConstant.ADD_CHECKGROUP_FAIL,null);
       }
    }
    //检查组数据回显
    @GetMapping("findById")
    public Result findById(int id){
       try {
           TCheckgroup tCheckgroup = tcheckgroupService.findById(id);
           return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,tCheckgroup);
       }catch (Exception e){
           e.printStackTrace();
           return new Result(false,MessageConstant.QUERY_CHECKGROUP_SUCCESS,null);
       }
    }

    //修改功能
    @PostMapping("update")
    public Result update(int[]checkitemIds,@RequestBody TCheckgroup checkgroup){
       try {
           tcheckgroupService.update(checkitemIds,checkgroup);
           return new Result(true,MessageConstant.EDIT_CHECKGROUP_SUCCESS,null);
       }catch (Exception e){
           e.printStackTrace();
           return new Result(false,MessageConstant.EDIT_CHECKGROUP_FAIL,null);
       }
    }

    //删除操作
    @GetMapping("delete")
    public Result delete(int id){
       try{
           tcheckgroupService.delete(id);
           return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS,null);
       }catch (Exception e){
           e.printStackTrace();
           return new Result(false,MessageConstant.DELETE_CHECKITEM_FAIL,null);
       }
    }
}




